﻿using System.Collections.Generic;
using System.Linq;
using ZilLion.Service.Core.DapperWrapper;
using ZilLion.Service.Core.DapperWrapper.SqlServer;
using ZilLion.Service.ZilLionOss.Domain.Entitys;
using ZilLion.Service.ZilLionOss.Domain.Repositorys.Interface;

namespace ZilLion.Service.ZilLionOss.Domain.Repositorys
{
    public class OssRouteRepositrory : SqlServerRespository<OssRouteInfoEntity>, IOssRouteRepositrory
    {
        public OssRouteRepositrory()
        {
            Context = new OssContext();
        }

        public IList<OssRouteInfoEntity> GetAllRoute()
        {
            var querysql = DapperHelper.CreateColSqlByMap<OssRouteInfoEntity>();
            var result = GetList($@"select {querysql} from oss_route_info "  );
            return result.ToList();
        }

        public IList<OssRouteInfoEntity> GetRouteByCompanykey(string companykey)
        {
            var querysql = DapperHelper.CreateColSqlByMap<OssRouteInfoEntity>("a");
            var result = GetList($@"select {querysql} from oss_route_info  a
                        inner join  oss_company_route b on b.routepath=a.routepath
                        where b.zlcompanykey=@companykey", new {companykey});
            return result.ToList();
        }

        public IList<OssRouteInfoEntity> GetRouteByCompanyModule(string companykey)
        {
            var querysql = DapperHelper.CreateColSqlByMap<OssRouteInfoEntity>("a");
            var result = GetList($@"select {querysql} from oss_route_info  a                    
                        inner join  oss_company_moudle b on b.moudlekey=a.routemodule
                        where b.zlcompanykey=@companykey", new {companykey});
            return result.ToList();
        }

        public IList<OssRouteInfoEntity> GetRoleRoutes(long roleid)
        {
            var querysql = DapperHelper.CreateColSqlByMap<OssRouteInfoEntity>("a");
            var result = GetList($@"select {querysql} from oss_route_info  a
                        inner join oss_role_page b on b.pageroute=a.routepath
                        where b.roleid=@roleid", new {roleid});
            return result.ToList();
        }
    }
}